package com.cw.jeeyt.service.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cw.jeeyt.service.bo.system.SysScaffoldModuleFileBo;
import com.cw.jeeyt.service.converter.system.SysScaffoldModuleFileConverter;
import com.cw.jeeyt.dao.intf.system.SysScaffoldModuleFileDao;
import com.cw.jeeyt.dao.model.system.SysScaffoldModuleFileDo;
import com.cw.jeeyt.dao.query.system.SysScaffoldModuleFileQuery;
import com.cw.jeeyt.service.intf.system.SysScaffoldModuleFileService;
import com.cw.lang.common.utils.SequenceTool;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.mybatis.dto.PageParam;

/**
 * 脚手架模块文件接口业务实现类
 *
 * @author admin
 * @date 2020-05-26 15:00:07
 */
@Service
public class SysScaffoldModuleFileServiceImpl implements SysScaffoldModuleFileService {
    @Autowired
    private SysScaffoldModuleFileDao sysScaffoldModuleFileDao;

    /**
     * 新增脚手架模块文件
     *
     * @param request 条件
     * @return Long
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long insert(SysScaffoldModuleFileBo request) {
        if (request == null) {
            return null;
        }
        Long id = SequenceTool.nextLongId();
        request.setId(id);
        sysScaffoldModuleFileDao.insertBySelective(SysScaffoldModuleFileConverter.bo2Do(request));
        return id;
    }

    /**
     * 更新脚手架模块文件
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean modify(SysScaffoldModuleFileBo request) {
        if (request == null) {
            return false;
        }
        sysScaffoldModuleFileDao.updateBySelective(SysScaffoldModuleFileConverter.bo2Do(request));
        return true;
    }

    /**
     * 删除脚手架模块文件
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(SysScaffoldModuleFileBo request) {
        if (request == null) {
            return false;
        }
        return sysScaffoldModuleFileDao.deleteByKey(request.getId()) > 0;
    }

    /**
     * 分页查询脚手架模块文件
     *
     * @param request 条件
     * @return PageInfo<SysScaffoldModuleFileBo>
     */
    @Override
    public PageInfo<SysScaffoldModuleFileBo> selectPage(SysScaffoldModuleFileBo request, PageParam pageParam) {
        PageInfo<SysScaffoldModuleFileDo> pageInfo = sysScaffoldModuleFileDao.selectPage(
            SysScaffoldModuleFileQuery.builder()
                .id(request.getId())
                .moduleId(request.getModuleId())
                .fileCode(request.getFileCode())
                .fileName(request.getFileName())
                .filePath(request.getFilePath())
                .fileType(request.getFileType())
                .fileContent(request.getFileContent())
                .fileComment(request.getFileComment())
                .build(), pageParam);
        List<SysScaffoldModuleFileBo> sysScaffoldModuleFiles = SysScaffoldModuleFileConverter.doList2BoList(
            pageInfo.getList());
        return new PageInfo<>(pageInfo, sysScaffoldModuleFiles);
    }

    /**
     * 查询脚手架模块文件详情信息
     *
     * @param request 条件
     * @return SysScaffoldModuleFileBo
     */
    @Override
    public SysScaffoldModuleFileBo queryDetail(SysScaffoldModuleFileBo request) {
        if (request == null) {
            return null;
        }
        return SysScaffoldModuleFileConverter.do2Bo(sysScaffoldModuleFileDao.selectByKey(request.getId()));
    }

    /**
     * 根据条件查询脚手架模块文件
     *
     * @param request 条件
     * @return List<SysScaffoldModuleFileBo>
     */
    @Override
    public List<SysScaffoldModuleFileBo> queryList(SysScaffoldModuleFileBo request) {
        if (request == null) {
            return null;
        }
        return SysScaffoldModuleFileConverter.doList2BoList(sysScaffoldModuleFileDao.selectByExample(
            SysScaffoldModuleFileQuery.builder()
                .id(request.getId())
                .moduleId(request.getModuleId())
                .fileCode(request.getFileCode())
                .fileName(request.getFileName())
                .filePath(request.getFilePath())
                .fileType(request.getFileType())
                .fileContent(request.getFileContent())
                .fileComment(request.getFileComment())
                .build()));
    }

    /**
     * 根据key查询脚手架模块文件
     *
     * @param id
     * @return
     */
    @Override
    public SysScaffoldModuleFileBo selectByKey(Long id) {

        return SysScaffoldModuleFileConverter.do2Bo(sysScaffoldModuleFileDao.selectByKey(id));
    }
}
